//
//  TouTiaoTabBarController.m
//  TouTiao
//
//  Created by 柴旭 on 16/9/12.
//  Copyright © 2016年 Match. All rights reserved.
//

#import "TouTiaoTabBarController.h"
#import "HomePageViewController.h"
#import "FriendViewController.h"
#import "MyViewController.h"
#import "VideoViewController.h"
#import "TouTiaoTabBarController.h"
#import "TouTiaoNavigationController.h"
#import "UIImage+image.h"
@interface TouTiaoTabBarController ()

@property(nonatomic,strong)MyViewController *me;

@end

@implementation TouTiaoTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    HomePageViewController *HomePage=[[HomePageViewController alloc]init];
    [self addChildController:HomePage andTitle:@"首页" andImage:@"home_tabbar_night" andSelectedImage:@"home_tabbar_press"];
    //2、最新的控制器
    VideoViewController *new=[[VideoViewController alloc] init];
    [self addChildController:new andTitle:@"视频" andImage:@"video_tabbar_night" andSelectedImage:@"video_tabbar_press"];

    
    //3、关注 的控制器
    FriendViewController *FriendTrends=[[FriendViewController alloc] init];
    [self addChildController:FriendTrends andTitle:@"关注" andImage:@"icon_details_like" andSelectedImage:@"icon_details_like_press_night"];
    
    //4、我的 控制器
    //加载箭头指向的控制器 "CXMeViewController.storyboard"
    //[self addChildController:_me andTitle:@"我的" andImage:@"mine_tabbar_night" andSelectedImage:@"mine_tabbar_press"];
    [self addMeItem];
    
}

#pragma mark 添加“我的”界面及Item设置
-(void)addMeItem
{
    UIStoryboard *board=[UIStoryboard storyboardWithName:@"MyViewController" bundle:nil];
    _me= [board instantiateInitialViewController];
    [self.me.tabBarItem setTitle:@"我的"];
    //定义可变字典变更字体颜色
    NSMutableDictionary *itemName = [NSMutableDictionary dictionary];
    itemName[NSForegroundColorAttributeName] = [UIColor blackColor];
    [self.me.tabBarItem setTitleTextAttributes:itemName forState:UIControlStateSelected];
    //设置item图片
    _me.tabBarItem.image = [UIImage imageNamed:@"mine_tabbar"];
    //设置选中时的图片
    UIImage *imge=[UIImage imageRender:@"mine_tabbar_press"];
    //禁止渲染
    _me.tabBarItem.selectedImage = imge;
    //添加控制器
    [self addChildViewController:_me];
    
}

-(void)addChildController:(UIViewController *)ViewControlle andTitle:(NSString*)Title andImage:(NSString*)Image andSelectedImage:(NSString*)SelectedImage{
    
    
    TouTiaoNavigationController *na=[[TouTiaoNavigationController alloc] initWithRootViewController:ViewControlle];
    na.tabBarItem.title = Title;
    //设置文本属性 可以设置文字的颜色 大小 间距等等
    //设置成可变字典
    NSMutableDictionary *attrs=[NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName]=[UIColor blackColor];
    [na.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateSelected];
    //字体大小 只能在默认状态下设置
    NSMutableDictionary *attrF=[NSMutableDictionary dictionary];
    attrF[NSFontAttributeName]=[UIFont systemFontOfSize:11];
    [na.tabBarItem setTitleTextAttributes:attrF forState:UIControlStateNormal];
    //没选中的图片
    na.tabBarItem.image = [UIImage imageNamed:Image];
    //禁止渲染 调用UIImage+UIimage.h
    UIImage *img=[UIImage imageRender:SelectedImage];
    
    //选中状态
    na.tabBarItem.selectedImage=img;
    [self addChildViewController:na];
    
}

@end
